﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Advanced_Pause_Resume_Abort_Client
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void leetSocket1_OnConnectedEVENT()
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new MethodInvoker(delegate() { leetSocket1_OnConnectedEVENT(); }));
                return;
            }

            label2.Text = "Connected: true";
        }
      
       

        int id;

        private void button2_Click(object sender, EventArgs e)
        {
            byte[] a = new byte[1024 * 1024 * 150]; // 150 MB
            progressBar1.Value = 0;
            id = leetSocket1.sendObject(a,  true, true, false);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            leetSocket1.ContinueCommand(id);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            leetSocket1.PauseCommand(id);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            leetSocket1.AbortCommand(id);

            // Reset the progressbar
            progressBar1.Value = 0;
           
        }

        private void leetSocket1_OnSendChunkEVENT(byte[] CustomHeader, ulong TotalLength, int SentBytes, ulong SentBytesAddition, bool isFinished, int CommandID)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new MethodInvoker(delegate() { leetSocket1_OnSendChunkEVENT(CustomHeader, TotalLength,  SentBytes,  SentBytesAddition,  isFinished,  CommandID); }));
                return;
            }

            int c = (int)(SentBytesAddition / (TotalLength / 100));

            //small optimization, if same value set, wont be set again -> less gui work 
            if (progressBar1.Value != c)
            {
                progressBar1.Value = c;
            }

        }
    }
}
